package site.service;

import org.n3r.eql.Eql;
import org.n3r.eql.EqlPage;
import org.springframework.stereotype.Service;
import site.config.CommonConfig;
import site.obj.Essay;
import site.obj.YearsCounts;

import java.util.List;
import java.util.Map;

@Service
public class EssayService {
    public void saveEssay(Map map) {
        new Eql().insert("essayAdd").params(map).execute();
    }

    public List<Essay> queryEssay(Map map,EqlPage eqlPage) {
        List<Essay> essay = new Eql().id("essayQuery").params(map).returnType(Essay.class).limit(eqlPage).execute();
        return essay;
    }

    public List<YearsCounts> queryTab(Map map) {
        List<YearsCounts> tab = new Eql().select("essayTabQuery").limit(10).params(map).returnType(YearsCounts.class).execute();
        return tab;
    }

    public List<String> queryOneTab(Map map) {
        List<String> tab = new Eql().select("essayOneTabQuery").params(map).returnType(String.class).execute();
        return tab;
    }

    public List<Essay> queryYearEssay(Map map) {
        List<Essay> tab = new Eql().select("essayYearQuery").params(map).limit(CommonConfig.PAGE_ROWS).returnType(Essay.class).execute();
        return tab;
    }

    public List<Essay> queryYearMore(Map map,EqlPage eqlPage) {
        List<Essay> tab = new Eql().select("essayYearQuery").params(map).limit(eqlPage).returnType(Essay.class).execute();
        return tab;
    }

    public void deleteEssay(String prodId) {
        new Eql().delete("essayDelete").params(prodId).execute();
    }

    public Essay queryEssayById(String prodId) {
        return new Eql().selectFirst("essayQueryById").params(prodId).returnType(Essay.class).execute();
    }

    public void updateEssay(Map map) {
        new Eql().update("essayUpdate").params(map).execute();
    }

    public List<Essay> queryAllEssay(Map map) {
        List<Essay> essay = new Eql().select("essayQuery").params(map).returnType(Essay.class).execute();
        return essay;
    }
}
